﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kugar.Core.Web;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Kugar.MVC.MobileUI.WeUI
{
    public abstract class WeUIElementBase
    {
        private ViewContext _viewContext = null;
        private Lazy<TagAttrbute> _attr = new Lazy<TagAttrbute>(attrLazy);

        internal TagAttrbute _attrs { get { return _attr.Value; } }

        internal WeUIElementBase(ViewContext viewContext)
        {
            _viewContext = viewContext;
        }

        public TagAttrbute Attributes => _attr.Value;



        public ViewContext ViewContext => WeUI.ViewContext;

        private static TagAttrbute attrLazy()
        {
            return new TagAttrbute();
        }

        protected IHtmlHelper Html => WeUI.HtmlHelper;


        protected MobileWeUI WeUI => (MobileWeUI)_viewContext.ViewBag.WebUI;
    }

    public abstract class ContainerBase: WeUIElementBase, IDisposable
    {
        protected ContainerBase(ViewContext viewContext) : base(viewContext)
        {
        }

        public abstract void Dispose();

        internal abstract ContainerBase RenderInternal();

        public override string ToString()
        {
            return "请调用Render函数输出容器";
            return base.ToString();
        }
        
    }

    public abstract class ControlBase : WeUIElementBase
    {
        public abstract MvcHtmlString Render();

        protected ControlBase(ViewContext viewContext) : base(viewContext)
        {
        }
    }
    
}